package top.wshape1.shiziapi.uaa.security;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import top.wshape1.shiziapi.common.constant.BizCodeEnum;
import top.wshape1.shiziapi.common.utils.R;
import top.wshape1.shiziapi.uaa.utils.ResponseUtil;

import java.io.IOException;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-08-30
 */

@Slf4j
public class OAuth2LoginFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        System.out.println("OAuth2LoginFailureHandler==============================");
        log.warn(exception.getMessage());
        ResponseUtil.writeResponse(response, R.instance(BizCodeEnum.OAUTH2_LOGIN_ERROR.code(), BizCodeEnum.OAUTH2_LOGIN_ERROR.msg()));
    }
}
